<script setup lang="ts">
import { useSound } from '@vueuse/sound'
import { sleep } from '@/utils/sleep'
import stepImg11 from '@/assets/common/12/step_02_14.jpg'
import stepImg12 from '@/assets/common/12/step_02_15.jpg'

import correctAnswerSfx from '@/assets/sound/correct_answer.mp3'

const { play } = useSound(correctAnswerSfx)
const currentStepImg = ref(stepImg11)

const intro = useIntro({
  steps: [

    {
      element: '#key',
      intro: '请再添加一个关键帧',
      position: 'top',
    },
  ],
}, [
  {
    target: 'key',
    posotionCallback(info: DOMRect) {
      return { x: info.left + 0, y: info.top + 0 }
    },
  },


])

const appStore = useAppStore()

const router = useRouter()

const secendBar = [
  {
    label: '调节',
    icon: 'adjust',
    callBack() {

    },
  },
  {
    label: '美颜',
    icon: 'beauty',
    callBack: () => { },
  },
  {
    label: '蒙版',
    icon: 'masking_out',
    callBack: () => { },
  },
  {
    icon: 'cut_picture',
    label: '切画中画',
    callBack: () => { },
  },
  {
    label: '防抖',
    icon: 'anti_shake',
    callBack() { },
  },
]
const isShow = ref(false)
const isUnmounted = ref(false); // 控制是否打断跳转
const set1 = setTimeout(async () => {
  intro.start()
}, 0);

onBeforeUnmount(() => {
  intro.stop()
  isUnmounted.value = true;
  console.log('Mask7_2 组件实例被卸载之前调用')
  clearTimeout(set1)
})
onUnmounted(() => {
  intro.stop()
  isUnmounted.value = true;
  console.log('Mask7_2 组件实例被卸载之前调用')
  clearTimeout(set1)
})
async function handleKey() {
  play()
  intro.stop() // 暂停指导
  currentStepImg.value = stepImg12
  // await sleep(1000)
  isShow.value = true;
  // await sleep(2000)
  // await sleep(500)
  setTimeout(() => {
    isShow.value = false;
    if (!isUnmounted.value) {
      router.push('Mask7_3')
    }

  }, 1000)
}
</script>

<template>
  <div class="flex-1 flex flex-col">
    <div class="no-click ">
      <!-- <div v-if="isShow" style="position: relative;width: 100%;
      height: 100%;">
        <i class="text">已再添加一个关键帧</i>
        <div class="xian1">
          <div class="jiantou"></div>
        </div>
        <div class="box1"></div>
      </div> -->
    </div>
    <div class=" flex justify-between h-4em p-x-1em pt-1em ">
      <div>
        <i class="i-material-symbols-close mr-1em" />
        <i class="i-material-symbols-help-outline" />
      </div>

      <div>
        <n-button type="info" size="small" class="mr-1em">
          1080P<i class="i-material-symbols-arrow-drop-down-rounded" />
        </n-button>
        <n-button id="exportBtn" type="primary" size="small">
          导出
        </n-button>
      </div>
    </div>

    <div class="bg-#0A0A0A ">
      <div id="Video1" class=" Video1" @click.stop="handleVideo1" />
      <div id="key" class=" key" @click.stop="handleKey" />
      <img :src="currentStepImg" class="w-full" style="height: 90%;">
    </div>

    <div class="flex h-4em items-center bg-#1C1C1C" style="position: absolute; bottom: 3px;width: 100%;height: ;">
      <div class="bg-#333 h-70% rounded flex-center m-x-0.5em">
        <i class="i-icon-park-outline-left" />
      </div>

      <div class="flex flex-1 overflow-x-auto scrollbar-none  ">
        <div v-for="item in secendBar" :id="item.icon" :key="item.label" class="flex-col-center flex-1 min-w-16%"
          @click.stop="item.callBack">
          <png-icon :icon="item.icon" class="text-2em m-b-3px" />
          <div class="text-sm">
            {{ item.label }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
@media screen and (min-width:440px) {
  .key {
    position: absolute;
    width: 31px;
    height: 39px;
    top: 338px;
    left: 256px;
  }

}

@media screen and (max-width:440px) {
  .key {
    position: absolute;
    width: 8vw;
    height: 10vw;
    top: 84vw;
    left: 64%;
  }

}
@media screen and (max-width:390px) {
  .key {
    position: absolute;
    width: 8vw;
    height: 10vw;
    top: 85vw;
    left: 64%;
  }

}
@media screen and (max-width:340px) {
  .key {
    position: absolute;
    width: 8vw;
    height: 10vw;
    top: 87vw;
    left: 64%;
  }

}

.no-click {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-color: transparent;
  z-index: 99;
}</style>